n = input()
m=0
count=0
if 999 <int(n)< 10000:
    for left in range(3):
        for right in range(left+1, 4):
            num = int(n[left:right+1])
            for d in range(2, num // 2):
                if num%1 == 0:
                    count=+1
            if count==0:
                if m<num and num!= 1:
                    m = num
if m!=0:
    print(m)
